<template>
  <div class="policy-management-container">
    <header class="policy-header">
      <h2>政策管理</h2>
    </header>
    
    <!-- 消息提示 -->
    <div v-if="message" class="message" :class="{ 'success': messageType === 'success', 'error': messageType === 'error' }">
      {{ message }}
    </div>
    
    <!-- 二级导航栏 -->
    <nav class="sub-nav">
      <ul class="sub-nav-list">
        <li class="sub-nav-item" :class="{ active: currentSubMenu === 'company-policy' }">
          <a href="#" @click.prevent="selectSubMenu('company-policy')">医药公司政策</a>
        </li>
        <li class="sub-nav-item" :class="{ active: currentSubMenu === 'medical-policy' }">
          <a href="#" @click.prevent="selectSubMenu('medical-policy')">医保政策</a>
        </li>
      </ul>
    </nav>
    
    <!-- 医药公司政策页面 -->
    <div v-if="currentSubMenu === 'company-policy'" class="policy-section">
      <div class="policy-header-row">
        <h3>医药公司政策管理</h3>
        <button v-if="props.userRole === 'admin'" @click="showCompanyPolicyForm = true" class="toggle-add-btn">
          添加政策
        </button>
      </div>
      <ul class="policy-list">
        <li v-for="(item, idx) in companyPolicies" :key="idx" @click="showCompanyPolicyDetail(item)" class="policy-item">
          <div class="policy-content">
            <h4>{{ item.name }}</h4>
            <p>{{ item.policy }}</p>
            <div class="policy-time">添加时间：{{ formatTime(item.updateTime) }}</div>
          </div>
          <div class="policy-actions" @click.stop>
            <button v-if="props.userRole === 'admin'" @click="openEditCompanyPolicyForm(idx)" class="edit-btn">修改</button>
            <button v-if="props.userRole === 'admin'" @click="deleteCompanyPolicy(idx)" class="delete-btn">删除</button>
          </div>
        </li>
      </ul>
    </div>

    <!-- 医保政策页面 -->
    <div v-if="currentSubMenu === 'medical-policy'" class="policy-section">
      <div class="policy-header-row">
        <h3>医保政策管理</h3>
        <button v-if="props.userRole === 'admin'" @click="showMedicalPolicyForm = true" class="toggle-add-btn">
          添加政策
        </button>
      </div>
      <ul class="policy-list">
        <li v-for="(item, idx) in medicalPolicies" :key="idx" @click="showMedicalPolicyDetail(item)" class="policy-item">
          <div class="policy-content">
            <h4>{{ item.title }}</h4>
            <p>{{ item.content }}</p>
            <div class="policy-time">添加时间：{{ formatTime(item.updateTime) }}</div>
          </div>
          <div class="policy-actions" @click.stop>
            <button v-if="props.userRole === 'admin'" @click="openEditMedicalPolicyForm(idx)" class="edit-btn">修改</button>
            <button v-if="props.userRole === 'admin'" @click="deleteMedicalPolicy(idx)" class="delete-btn">删除</button>
          </div>
        </li>
      </ul>
    </div>

    <!-- 医药公司政策添加弹窗 -->
    <div v-if="showCompanyPolicyForm && props.userRole === 'admin'" class="modal-overlay" @click="closeCompanyPolicyForm">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>添加医药公司政策</h3>
          <button @click="closeCompanyPolicyForm" class="close-btn">&times;</button>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label>政策标题：</label>
            <input v-model="newCompanyPolicy.name" placeholder="请输入政策标题" class="policy-input" />
          </div>
          <div class="form-group">
            <label>政策内容：</label>
            <textarea v-model="newCompanyPolicy.policy" placeholder="请输入政策内容" class="policy-textarea"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button @click="addCompanyPolicy" class="add-btn" :disabled="loading">{{ loading ? '添加中...' : '确认添加' }}</button>
          <button @click="closeCompanyPolicyForm" class="cancel-btn">取消</button>
        </div>
      </div>
    </div>

    <!-- 医药公司政策修改弹窗 -->
    <div v-if="showEditCompanyPolicyForm && props.userRole === 'admin'" class="modal-overlay" @click="closeEditCompanyPolicyForm">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>修改医药公司政策</h3>
          <button @click="closeEditCompanyPolicyForm" class="close-btn">&times;</button>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label>政策标题：</label>
            <input v-model="editCompanyPolicy.name" placeholder="请输入政策标题" class="policy-input" />
          </div>
          <div class="form-group">
            <label>政策内容：</label>
            <textarea v-model="editCompanyPolicy.policy" placeholder="请输入政策内容" class="policy-textarea"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button @click="updateCompanyPolicy" class="update-btn" :disabled="loading">{{ loading ? '修改中...' : '确认修改' }}</button>
          <button @click="closeEditCompanyPolicyForm" class="cancel-btn">取消</button>
        </div>
      </div>
    </div>

    <!-- 医保政策添加弹窗 -->
    <div v-if="showMedicalPolicyForm && props.userRole === 'admin'" class="modal-overlay" @click="closeMedicalPolicyForm">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>添加医保政策</h3>
          <button @click="closeMedicalPolicyForm" class="close-btn">&times;</button>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label>政策标题：</label>
            <input v-model="newMedicalPolicy.title" placeholder="请输入政策标题" class="policy-input" />
          </div>
          <div class="form-group">
            <label>政策内容：</label>
            <textarea v-model="newMedicalPolicy.content" placeholder="请输入政策内容" class="policy-textarea"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button @click="addMedicalPolicy" class="add-btn">确认添加</button>
          <button @click="closeMedicalPolicyForm" class="cancel-btn">取消</button>
        </div>
      </div>
    </div>

    <!-- 医保政策修改弹窗 -->
    <div v-if="showEditMedicalPolicyForm && props.userRole === 'admin'" class="modal-overlay" @click="closeEditMedicalPolicyForm">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>修改医保政策</h3>
          <button @click="closeEditMedicalPolicyForm" class="close-btn">&times;</button>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label>政策标题：</label>
            <input v-model="editMedicalPolicy.title" placeholder="请输入政策标题" class="policy-input" />
          </div>
          <div class="form-group">
            <label>政策内容：</label>
            <textarea v-model="editMedicalPolicy.content" placeholder="请输入政策内容" class="policy-textarea"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button @click="updateMedicalPolicy" class="update-btn" :disabled="loading">{{ loading ? '修改中...' : '确认修改' }}</button>
          <button @click="closeEditMedicalPolicyForm" class="cancel-btn">取消</button>
        </div>
      </div>
    </div>

    <!-- 医药公司政策详细信息弹窗 -->
    <div v-if="showCompanyPolicyDetailModal" class="modal-overlay" @click="closeCompanyPolicyDetail">
      <div class="modal-content detail-modal" @click.stop>
        <div class="modal-header">
          <h3>医药公司政策详情</h3>
          <button @click="closeCompanyPolicyDetail" class="close-btn">&times;</button>
        </div>
        <div class="modal-body">
          <div class="detail-item">
            <label>政策标题：</label>
            <div class="detail-content">{{ selectedCompanyPolicy.name }}</div>
          </div>
          <div class="detail-item">
            <label>政策内容：</label>
            <div class="detail-content">{{ selectedCompanyPolicy.policy }}</div>
          </div>
          <div class="detail-item">
            <label>添加时间：</label>
            <div class="detail-content">{{ formatTime(selectedCompanyPolicy.updateTime) }}</div>
          </div>
        </div>
        <div class="modal-footer">
          <button @click="closeCompanyPolicyDetail" class="cancel-btn">关闭</button>
        </div>
      </div>
    </div>

    <!-- 医保政策详细信息弹窗 -->
    <div v-if="showMedicalPolicyDetailModal" class="modal-overlay" @click="closeMedicalPolicyDetail">
      <div class="modal-content detail-modal" @click.stop>
        <div class="modal-header">
          <h3>医保政策详情</h3>
          <button @click="closeMedicalPolicyDetail" class="close-btn">&times;</button>
        </div>
        <div class="modal-body">
          <div class="detail-item">
            <label>政策标题：</label>
            <div class="detail-content">{{ selectedMedicalPolicy.title }}</div>
          </div>
          <div class="detail-item">
            <label>政策内容：</label>
            <div class="detail-content">{{ selectedMedicalPolicy.content }}</div>
          </div>
          <div class="detail-item">
            <label>添加时间：</label>
            <div class="detail-content">{{ formatTime(selectedMedicalPolicy.updateTime) }}</div>
          </div>
        </div>
        <div class="modal-footer">
          <button @click="closeMedicalPolicyDetail" class="cancel-btn">关闭</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import axios from 'axios';

const props = defineProps({
  currentSubMenu: {
    type: String,
    default: 'company-policy'
  },
  account: {
    type: String,
    default: ''
  },
  userRole: {
    type: String,
    default: ''
  }
});

const emit = defineEmits(['update:currentSubMenu']);

// 消息提示
const message = ref('');
const messageType = ref('');
const loading = ref(false);

// 显示消息提示
function showMessage(msg, type = 'success') {
  message.value = msg;
  messageType.value = type;
  setTimeout(() => {
    message.value = '';
    messageType.value = '';
  }, 3000);
}

// 公司政策数据
const companyPolicies = ref([]);

// 查询所有公司政策
async function fetchCompanyPolicies() {
  try {
    loading.value = true;
    const storedToken = localStorage.getItem('token');
    const response = await axios.get('http://47.93.134.56:8800/company_policy/getall', {
      headers: {
        'token': storedToken
      }
    });
    if (response.data.code === 200) {
      companyPolicies.value = response.data.data.map(item => ({ name: item.name, policy: item.policy, id: item.id, updateTime: item.updateTime }));
    } else {
      showMessage(response.data.msg || '获取公司政策失败', 'error');
    }
  } catch (error) {
    if (error.response && error.response.data && typeof error.response.data.msg === 'string') {
      showMessage(error.response.data.msg, 'error');
    } else {
      showMessage('网络错误', 'error');
    }
  } finally {
    loading.value = false;
  }
}

// 添加公司政策
async function addCompanyPolicy() {
  if (!newCompanyPolicy.value.name || !newCompanyPolicy.value.policy) {
    showMessage('请填写完整的政策信息', 'error');
    return;
  }
  try {
    loading.value = true;
    const storedToken = localStorage.getItem('token');
    const response = await axios.post('http://47.93.134.56:8800/company_policy/add', newCompanyPolicy.value, {
      headers: {
        'token': storedToken
      }
    });
    if (response.data.code === 200) {
      showMessage(response.data.msg || '添加医药公司政策成功');
      showCompanyPolicyForm.value = false;
      newCompanyPolicy.value = { name: '', policy: '' };
      await fetchCompanyPolicies();
    } else {
      showMessage(response.data.msg || '添加医药公司政策失败', 'error');
    }
  } catch (error) {
    showMessage(error.response?.data?.msg || '网络错误', 'error');
  } finally {
    loading.value = false;
  }
}

// 删除公司政策
async function deleteCompanyPolicy(idx) {
  const policy = companyPolicies.value[idx];
  if (!policy) return;
  if (!confirm('确定要删除该政策吗？')) return;
  try {
    loading.value = true;
    const storedToken = localStorage.getItem('token');
    const response = await axios.delete(`http://47.93.134.56:8800/company_policy/delete/${policy.id}`, {
      headers: {
        'token': storedToken
      }
    });
    if (response.data.code === 200) {
      showMessage(response.data.msg || '删除医药公司政策成功');
      await fetchCompanyPolicies();
    } else {
      showMessage(response.data.msg || '删除医药公司政策失败', 'error');
    }
  } catch (error) {
    showMessage(error.response?.data?.msg || '网络错误', 'error');
  } finally {
    loading.value = false;
  }
}

// 打开编辑公司政策弹窗
function openEditCompanyPolicyForm(idx) {
  const policy = companyPolicies.value[idx];
  if (!policy) return;
  editCompanyPolicy.value = { name: policy.name, policy: policy.policy, id: policy.id };
  showEditCompanyPolicyForm.value = true;
}

// 修改公司政策
async function updateCompanyPolicy() {
  if (!editCompanyPolicy.value.name || !editCompanyPolicy.value.policy) {
    showMessage('请填写完整的政策信息', 'error');
    return;
  }
  try {
    loading.value = true;
    const storedToken = localStorage.getItem('token');
    const response = await axios.post('http://47.93.134.56:8800/company_policy/update', editCompanyPolicy.value, {
      headers: {
        'token': storedToken
      }
    });
    if (response.data.code === 200) {
      showMessage(response.data.msg || '修改医药公司政策成功', 'success');
      showEditCompanyPolicyForm.value = false;
      editCompanyPolicy.value = { name: '', policy: '', id: 0 };
      await fetchCompanyPolicies();
    } else {
      showMessage(response.data.msg || '修改医药公司政策失败', 'error');
    }
  } catch (error) {
    if (error.response && error.response.data && typeof error.response.data.msg === 'string') {
      showMessage(error.response.data.msg, 'error');
    } else {
      showMessage('网络错误', 'error');
    }
  } finally {
    loading.value = false;
  }
}

// 页面加载时获取公司政策
onMounted(() => {
  fetchCompanyPolicies();
});

// 医保政策数据
const medicalPolicies = ref([]);

// 查询所有医保政策
async function fetchMedicalPolicies() {
  try {
    loading.value = true;
    const storedToken = localStorage.getItem('token');
    const response = await axios.get('http://47.93.134.56:8800/medical_policy/getall', {
      headers: {
        'token': storedToken
      }
    });
    if (response.data.code === 200) {
      medicalPolicies.value = response.data.data.map(item => ({ title: item.name, content: item.policy, id: item.id, updateTime: item.updateTime }));
    } else {
      showMessage(response.data.msg || '获取医保政策失败', 'error');
    }
  } catch (error) {
    showMessage(error.response?.data?.msg || '网络错误', 'error');
  } finally {
    loading.value = false;
  }
}

// 添加医保政策
async function addMedicalPolicy() {
  if (!newMedicalPolicy.value.title || !newMedicalPolicy.value.content) {
    showMessage('请填写完整的政策信息', 'error');
    return;
  }
  try {
    loading.value = true;
    const storedToken = localStorage.getItem('token');
    const response = await axios.post('http://47.93.134.56:8800/medical_policy/add', {
      name: newMedicalPolicy.value.title,
      policy: newMedicalPolicy.value.content
    }, {
      headers: {
        'token': storedToken
      }
    });
    if (response.data.code === 200) {
      showMessage(response.data.msg || '添加医保政策成功');
      showMedicalPolicyForm.value = false;
      newMedicalPolicy.value = { title: '', content: '' };
      await fetchMedicalPolicies();
    } else {
      showMessage(response.data.msg || '添加医保政策失败', 'error');
    }
  } catch (error) {
    showMessage(error.response?.data?.msg || '网络错误', 'error');
  } finally {
    loading.value = false;
  }
}

// 删除医保政策
async function deleteMedicalPolicy(idx) {
  const policy = medicalPolicies.value[idx];
  if (!policy) return;
  if (!confirm('确定要删除该政策吗？')) return;
  try {
    loading.value = true;
    const storedToken = localStorage.getItem('token');
    const response = await axios.delete(`http://47.93.134.56:8800/medical_policy/delete/${policy.id}`, {
      headers: {
        'token': storedToken
      }
    });
    if (response.data.code === 200) {
      showMessage(response.data.msg || '删除医保政策成功');
      await fetchMedicalPolicies();
    } else {
      showMessage(response.data.msg || '删除医保政策失败', 'error');
    }
  } catch (error) {
    showMessage(error.response?.data?.msg || '网络错误', 'error');
  } finally {
    loading.value = false;
  }
}

// 打开编辑医保政策弹窗
function openEditMedicalPolicyForm(idx) {
  const policy = medicalPolicies.value[idx];
  if (!policy) return;
  editMedicalPolicy.value = { title: policy.title, content: policy.content, id: policy.id };
  showEditMedicalPolicyForm.value = true;
}

// 修改医保政策
async function updateMedicalPolicy() {
  if (!editMedicalPolicy.value.title || !editMedicalPolicy.value.content) {
    showMessage('请填写完整的政策信息', 'error');
    return;
  }
  try {
    loading.value = true;
    const storedToken = localStorage.getItem('token');
    const response = await axios.post('http://47.93.134.56:8800/medical_policy/update', {
      id: editMedicalPolicy.value.id,
      name: editMedicalPolicy.value.title,
      policy: editMedicalPolicy.value.content
    }, {
      headers: {
        'token': storedToken
      }
    });
    if (response.data.code === 200) {
      showMessage(response.data.msg || '修改医保政策成功', 'success');
      showEditMedicalPolicyForm.value = false;
      editMedicalPolicy.value = { title: '', content: '', id: 0 };
      await fetchMedicalPolicies();
    } else {
      showMessage(response.data.msg || '修改医保政策失败', 'error');
    }
  } catch (error) {
    showMessage(error.response?.data?.msg || '网络错误', 'error');
  } finally {
    loading.value = false;
  }
}

// 页面加载时获取医保政策
onMounted(() => {
  fetchCompanyPolicies();
  fetchMedicalPolicies();
});

// 新增政策表单数据
const newCompanyPolicy = ref({
  name: '',
  policy: ''
});

// 修改政策表单数据
const editCompanyPolicy = ref({
  name: '',
  policy: '',
  id: 0
});

// 修改医保政策表单数据
const editMedicalPolicy = ref({
  title: '',
  content: '',
  id: 0
});

const newMedicalPolicy = ref({
  title: '',
  content: ''
});

// 控制表单显示状态
const showCompanyPolicyForm = ref(false);
const showMedicalPolicyForm = ref(false);
const showEditCompanyPolicyForm = ref(false);
const showEditMedicalPolicyForm = ref(false);

// 控制详细信息弹窗显示状态
const showCompanyPolicyDetailModal = ref(false);
const showMedicalPolicyDetailModal = ref(false);

// 选中的政策数据
const selectedCompanyPolicy = ref({});
const selectedMedicalPolicy = ref({});

function closeCompanyPolicyForm() {
  newCompanyPolicy.value = { name: '', policy: '' };
  showCompanyPolicyForm.value = false;
}

function closeEditCompanyPolicyForm() {
  showEditCompanyPolicyForm.value = false;
  editCompanyPolicy.value = { name: '', policy: '', id: 0 };
}

function closeMedicalPolicyForm() {
  newMedicalPolicy.value = { title: '', content: '' };
  showMedicalPolicyForm.value = false;
}

function closeEditMedicalPolicyForm() {
  showEditMedicalPolicyForm.value = false;
  editMedicalPolicy.value = { title: '', content: '', id: 0 };
}

// 二级导航切换
function selectSubMenu(subMenu) {
  emit('update:currentSubMenu', subMenu);
}

// 格式化时间
function formatTime(timestamp) {
  const date = new Date(timestamp);
  return date.toLocaleString();
}

function showCompanyPolicyDetail(policy) {
  selectedCompanyPolicy.value = policy;
  showCompanyPolicyDetailModal.value = true;
}

function showMedicalPolicyDetail(policy) {
  selectedMedicalPolicy.value = policy;
  showMedicalPolicyDetailModal.value = true;
}

function closeCompanyPolicyDetail() {
  showCompanyPolicyDetailModal.value = false;
}

function closeMedicalPolicyDetail() {
  showMedicalPolicyDetailModal.value = false;
}
</script>

<style scoped>
.policy-management-container {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow: hidden;
}

/* 消息提示样式 */
.message {
  padding: 12px 16px;
  margin-bottom: 15px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
}

.message.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.message.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.policy-header {
  margin-bottom: 20px;
}

/* 二级导航栏样式 */
.sub-nav {
  margin-bottom: 30px;
  border-bottom: 1px solid #e0e0e0;
}

.sub-nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 0;
}

.sub-nav-item {
  position: relative;
}

.sub-nav-item a {
  display: block;
  padding: 15px 25px;
  color: #666;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
  border-bottom: 3px solid transparent;
}

.sub-nav-item a:hover {
  color: #333;
  background-color: #f8f9fa;
}

.sub-nav-item.active a {
  color: #3498db;
  border-bottom-color: #3498db;
  background-color: #f8f9fa;
}

.sub-nav-item.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background-color: #fff;
}

.policy-section {
  flex: 1;
  overflow-y: auto;
}

.policy-section h3 {
  margin: 0 0 20px 0;
  color: #333;
  font-size: 1.3rem;
  font-weight: 600;
}

.policy-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.policy-header-row h3 {
  margin: 0;
  color: #333;
  font-size: 1.3rem;
  font-weight: 600;
}

.policy-list {
  list-style: none;
  padding: 0;
  margin: 0 0 30px 0;
}

.policy-list li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px;
  margin-bottom: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  transition: all 0.2s ease;
  cursor: pointer;
}

.policy-list li:hover {
  background: #e9ecef;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

.policy-item {
  cursor: pointer;
}

.policy-content {
  flex: 1;
  margin-right: 20px;
}

.policy-content h4 {
  margin: 0 0 10px 0;
  color: #333;
  font-size: 1.1rem;
  font-weight: 600;
}

.policy-content p {
  margin: 0 0 10px 0;
  color: #666;
  line-height: 1.6;
}

.policy-time {
  margin: 0;
  color: #999;
  font-size: 0.85rem;
  font-style: italic;
}

.policy-actions {
  display: flex;
  gap: 10px;
}

.edit-btn {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.edit-btn:hover {
  background-color: #c3e6cb;
  color: #155724;
}

.delete-btn {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.delete-btn:hover {
  background-color: #f5c6cb;
  color: #721c24;
}

.toggle-add-btn {
  background: #3498db;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.toggle-add-btn:hover {
  background: #217dbb;
}

.update-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.update-btn:hover {
  background: #218838;
}

.update-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.cancel-btn {
  background: #95a5a6;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.cancel-btn:hover {
  background: #7f8c8d;
}

/* 弹窗样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideIn 0.3s ease;
  border: 1px solid #e0e0e0;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-50px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 25px 25px 20px 25px;
  border-bottom: 2px solid #3498db;
}

.modal-header h3 {
  margin: 0;
  color: #2c3e50;
  font-size: 1.4rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.close-btn:hover {
  background: #f0f0f0;
  color: #333;
  transform: scale(1.1);
}

.modal-body {
  padding: 25px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #34495e;
  font-weight: 500;
  font-size: 0.95rem;
}

.policy-input, .policy-textarea {
  width: 100%;
  padding: 12px 15px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  box-sizing: border-box;
  background: #fafbfc;
  transition: all 0.3s ease;
}

.policy-input:focus, .policy-textarea:focus {
  outline: none;
  border-color: #3498db;
  background: white;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.policy-textarea {
  min-height: 100px;
  resize: vertical;
}

.modal-footer {
  display: flex;
  justify-content: center;
  gap: 15px;
  padding: 20px 25px 25px 25px;
  border-top: 1px solid #e0e0e0;
}

.add-btn, .update-btn, .cancel-btn {
  padding: 12px 30px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.3s ease;
  min-width: 100px;
}

.add-btn, .update-btn {
  background: linear-gradient(135deg, #3498db, #2980b9);
  color: white;
  box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
}

.add-btn:hover, .update-btn:hover {
  background: linear-gradient(135deg, #2980b9, #1f5f8b);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
}

.cancel-btn {
  background: linear-gradient(135deg, #95a5a6, #7f8c8d);
  color: white;
  box-shadow: 0 4px 15px rgba(149, 165, 166, 0.3);
}

.cancel-btn:hover {
  background: linear-gradient(135deg, #7f8c8d, #6c7b7d);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(149, 165, 166, 0.4);
}

/* 禁用状态 */
.add-btn:disabled, .update-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .sub-nav-list {
    flex-direction: column;
  }
  
  .sub-nav-item a {
    padding: 12px 20px;
    text-align: center;
  }
  
  .policy-list li {
    flex-direction: column;
    align-items: stretch;
  }
  
  .policy-content {
    margin-right: 0;
    margin-bottom: 15px;
  }
  
  .policy-actions {
    flex-direction: column;
  }
  
  .policy-actions button {
    width: 100%;
  }
  
  .modal-content {
    width: 95%;
    margin: 10px;
  }
  
  .modal-footer {
    flex-direction: column;
  }
  
  .modal-footer button {
    width: 100%;
  }
}

/* 详细信息弹窗样式 */
.detail-modal {
  max-width: 600px;
}

.detail-item {
  margin-bottom: 20px;
}

.detail-item label {
  display: block;
  margin-bottom: 8px;
  color: #333;
  font-weight: 600;
  font-size: 0.95rem;
}

.detail-content {
  padding: 12px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  color: #333;
  line-height: 1.6;
  min-height: 20px;
  word-wrap: break-word;
}
</style>